const express = require('express');
const router = express.Router();

const expressJoi = require('@escook/express-joi');
const { 
    addArticleCheck,
    findArticleCheck,
    updateArticleCheck,
    deleteArticleCheck,
    statisticsCheck,
    recordVisitCheck,
    updateViewCountCheck,
    getArticleDetail
} = require('../utils/check');
const articleController = require('../controllers/articleController');

/**
 * 文章添加接口
 * POST /article/add
 */
router.post('/add', expressJoi(addArticleCheck), articleController.addArticle);

/**
 * 文章查询接口
 * GET /article/find
 */
router.get('/find', expressJoi(findArticleCheck), articleController.listArticle);

/**
 * 文章修改接口
 * 改为PUT方法更符合RESTful规范
 * PUT /article/update
 */
router.put('/update', expressJoi(updateArticleCheck), articleController.updateArticle);
/**
 * 文章删除接口
 * DELETE /article/delete
 */
router.delete('/delete', expressJoi(deleteArticleCheck), articleController.deleteArticle);

/**
 * 根据文章ID获取文章详情接口
 * GET /article/detail
 * /article/detail?id=1
 */
router.get('/detail', expressJoi(getArticleDetail), articleController.getArticleDetail);

/**
 * 文章统计接口
 * GET /article/statistics
 */
router.get('/statistics', expressJoi(statisticsCheck), articleController.getArticleStatistics);

/**
 * 新增：访问日志记录接口
 * POST /article/visit
 */
router.post('/visit', expressJoi(recordVisitCheck), articleController.recordArticleVisit);

/**
 * 新增：阅读量更新接口
 * PUT /article/view
 */
router.put('/view', expressJoi(updateViewCountCheck), articleController.incrementArticleView);

module.exports = router;